package org.an.proj.contacts.net.service.retrofit.upload;

import java.io.IOException;
import okhttp3.Interceptor;
import okhttp3.Response;

/**
 * 创建时间：2016年10月12日10:55 <br>
 * 作者：fuchaoyang <br>
 * 描述：上传Interceptor
 */
public class UploadInterceptor implements Interceptor {
  private ProgressListener progressListener;

  public UploadInterceptor(ProgressListener progressListener) {
    this.progressListener = progressListener;
  }

  @Override public Response intercept(Chain chain) throws IOException {
    okhttp3.Response originalResponse = chain.proceed(chain.request());

    return originalResponse.newBuilder()
        .body(new ProgressResponseBody(originalResponse.body(), progressListener))
        .build();
  }
}
